package com.lzj.friend;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class FriendJob {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //读取配置文件
        Configuration configuration = new Configuration(true);
        configuration.set("mapreduce.framework.name", "local");
        //创建Job
        Job job = Job.getInstance(configuration);
        //设置Job的参数
        job.setJobName("friend-" + System.currentTimeMillis());
        job.setJarByClass(FriendJob.class);
        job.setNumReduceTasks(1);
        //设置要处理文件路径
        FileInputFormat.setInputPaths(job, new Path("/lzj/friend.txt"));
        //设置要输出的结果路径
        FileOutputFormat.setOutputPath(job, new Path("/lzj/result/friend-" + System.currentTimeMillis()));
        //设置Map要输出的数据类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        //设置Map类
        job.setMapperClass(FriendMapper.class);
        //设置Reduce类
        job.setReducerClass(FriendReducer.class);
        //提交任务
        job.waitForCompletion(true);


    }

}
